import 'package:flutter/material.dart';

class AnimatedDemo extends StatefulWidget {
  @override
  _AnimatedDemoState createState() => _AnimatedDemoState();
}

class _AnimatedDemoState extends State<AnimatedDemo> {
  // Widget _animatedsitcherWidget = Text('switcher', key: ValueKey('bbs'));
  // CrossFadeState _showState = CrossFadeState.showFirst;
  double tweenOpacity = 0.2;

  void _changeState() {
    setState(() {
      // _animatedsitcherWidget = Text('switcher change', key: ValueKey('abs'));
      // _showState = CrossFadeState.showSecond;
      tweenOpacity = tweenOpacity >= 1 ? 0.2 : tweenOpacity + 0.2;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('AnimatedDemo')),
      body: Center(
        child: TweenAnimationBuilder(
          duration: Duration(seconds: 1),
          tween: Tween(end: tweenOpacity),
          builder: (BuildContext context, double value, Widget child) {
            return Opacity(
              opacity: value,
              child: Container(
                width: 300,
                height: 300,
                color: Colors.blue,
              ),
            );
          },
        ),
        // AnimatedContainer(
        //   duration: Duration(milliseconds: 500),
        //   width: 200,
        //   height: 300,
        //   color: Colors.blue,
        //   // child: AnimatedSwitcher(
        //   //   duration: Duration(seconds: 2),
        //   //   child: _animatedsitcherWidget,
        //   // ),
        //   child: AnimatedCrossFade(
        //     firstChild: Text('switcher', key: ValueKey('bbs')),
        //     secondChild: Text('switcher change', key: ValueKey('abs')),
        //     crossFadeState: _showState,
        //     duration: Duration(milliseconds: 500),
        //   ),
        // ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _changeState,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }
}
